<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />

<title>Getting Started with Sencha Touch</title>

<link rel="stylesheet" type="text/css" href="examples/resources/shared/css/style.css" media="all" />
</head>
<body>
<a href="http://www.sencha.com/" id="logo">Sencha Touch - HTML5 Mobile Application Framework</a>

<h1>Getting Started with Sencha Touch</h1>

<p>This document describes how to get started with Sencha Touch. It explains the basic steps for using Sencha Touch to create Web applications for touch-based devices. Additionally, it provides detailed steps for creating the GeoTweets example application, which is one of the example applications included in the Sencha Touch release package.</p>

<p>This document is written for Web developers who want to quickly get started using Sencha Touch to create Web applications for touch-based devices. It assumes you have downloaded the Sencha Touch libraries. have a properly installed and configured Web server, and are familiar with Web application development and concepts such as JavaScript, HTML, Cascading Style Sheets (CSS), Web servers, and so forth.</p>

<p>This document contains the following sections:</p>
	<ul>
		<li><a href="#Intro">Introduction to Sencha Touch</a></li>
		<li><a href="#MainSteps">Using Sencha Touch: Main Steps</a></li>
		<li><a href="#DetailedSteps">Using Sencha Touch: Detailed Steps for Creating the GeoTweets Application</a></li>
		<li><a href="#Summary">Summary and Further Reading</a></li>
	</ul>

<h2><a name="Intro"></a>Introduction to Sencha Touch</h2>
<p>Sencha Touch is a JavaScript framework for creating Web applications targeted to touch-based devices. With Sencha Touch, you can use the skills you already possess to create an elegant and consistent user experience with minimal effort. Sencha Touch makes use of technologies such as HTML and CSS to provide native-quality application experiences without needing plugins.</>

<h2><a name="MainSteps"></a>Using Sencha Touch: Main Steps</h2>

<ol>
	<li><a href="#MainSetUp">Set up your Environment</a></li>
	<li><a href="#MainCreateHTML">Create the HTML File</a></li>
	<li><a href="#MainCreateJS">Create the Application JavaScript File</a></li>
	<li><a href="#MainTest">Test the Application</a></li>
	<li><a href="#MainUpdateForProd">Update the Application for Production</a></li>
	<li><a href="#MainPutIntoProd">Put the Application into Production</a></li>
</ol>
<p>To use Sencha Touch to create JavaScript applications for touch-based devices, follow these main steps:</p>
<ol>
	<h3><li><a name="MainSetUp"></a>Set up your Environment</li></h3>
		<ul>
			<li>Download the Sencha Touch Libraries.</li>
			<li>Make sure your development environment is set up.</li>
			<li>Make sure your development and production Web servers are properly installed and configured.</li>
			<li>Know the name of the CSS file you want your application to use. You will need this file name when you create the application HTML file in the next step.</li>
		</ul>

	<h3><li><a name="MainCreateHTML"></a>Create the HTML File</li></h3>
		<p>In the editor of your choice, create the HTML file for your application. For an example of an application HTML file, see <a href="#DetCreatingHTML">Detailed Steps: Creating the HTML File</a>.</p>
		<p>The application HTML file is where you specify links to:</p>
			<ul>
				<li>the default Sencha Touch cascading style sheet (CSS) file, <strong>sencha-touch.css</strong>.</li>
				<li>the application's CSS file. For example, <strong><em>mycss</em>.css</strong>.</li>
				<li>the version of the Sencha Touch library you want the application to use.
				    <p>Sencha recommends that you:
					<ul>
						<li>use the debug version of the library, <strong>sencha-touch-debug.js</strong>, during application development and testing. The debug version helps you detect and troubleshoot errors, as well as to see exactly where in the library errors occur.</li>
						<li>change the HTML file to link to the production version of the library, <strong>sencha-touch.js</strong>, before you put your application into production. For more information see <a href="#MainUpdateForProd">Update the Application for Production</a>.
					</p></ul></li>
				<li>the application's JavaScript file, which you will create in the next step. For example, <strong><em>myapp</em>.js</strong>.</li>
			</ul>
		<p>Save the HTML file with a logical name such as <em>myapp.html</em>. After you have finished writing the application and have put it on your local Web server, you will point your browser to this file name on your local Web server in order to view and test your application.</p>

	<h3><li><a name="MainCreateJS"></a>Create the Application JavaScript File</li></h3>
		<ul>
			<li>In the editor of your choice, create the JavaScript file for your application. For an example of an application JavaScript file, see <a href="#DetCreatingJS">Creating the Application JavaScript File</a>.</li>
			<li>Save your file with the desired name and <strong>.js</strong> extension. For example, <strong><em>myapp</em>.js</strong>. Link to this file in the HTML file you created in the previous step.</li>
		</ul>

	<h3><li><a name="MainTest"></a>Test the Application</li></h3>
		<p>To test your application:
		<ol>
			<li>Upload the library files to the destination directory on your Web server.</li>
			<li>Upload the application files (html, js, and css) and all referenced files to the destination directory on your Web server.</li>
			<li>Point your browser to <strong>http://<em>localhost:8080/myapp.html</em></strong> where:
				<ul>
					<li><em>localhost</em> is the Web server host name or IP address</li>
					<li><em>8080</em> is the Web server port number</li>
					<li><em>myapp.html</em> is the name of the application HTML file</li>
				</ul>
		</ol>
		</p>

	<h3><li><a name="MainUpdateForProd"></a>Update the Application for Production</li></h3>
		<p>When you are done testing your application, change the application's HTML file to point to the production version of the Sencha Touch library. To do so:
			<ol>
				<li>Open the HTML file.</li>
				<li>Locate the code that specifies the Sencha Touch Library. For example:</li>
	<pre>
	&lt;!-- Sencha Touch JS --&gt;
	&lt;script type=&quot;text/javascript&quot; src=&quot;../../sencha-touch-debug.js&quot;&gt;&lt;/script&gt;
	</pre>
				<li>Replace <em>sencha-touch-debug.js</em> with <em>sencha-touch.js</em>. <strong>sencha-touch.js</strong> is optimized for production. It is compressed and does not contain documentation.
				</li>
				<li>Save the HTML file.</li>
			</ol>
		</p>

	<h3><li><a name="MainPutIntoProd"></a>Put the Application into Production</li></h3>
		<p>When your application is ready for production, simply put a copy of the application's source files and any other files the application references on your production Web server.</p>
</ol>

<h2><a name="DetailedSteps"></a>Using Sencha Touch: Detailed Steps for Creating the GeoTweets Application</h2>
	<p>This section expands on the main steps described in the previous section by walking you step-by-step through the process of creating a Sencha Touch application. This complete source for the application, GeoTweets, can be found in the <strong>/examples/guide</strong> subdirectory in the Sencha Touch release package.
<p>The GeoTweets application demonstrates how easy it is to use Sencha Touch to create a simple yet powerful application. The application:
	<ul>
		<li>uses Geolocation to find nearby tweets from Twitter.</li>
		<li>shows the tweets in map and list views as cards which display on tabs.</li>
		<li>uses a special animation effect when application users switch between the cards.</li>
	</ul>
	The following sections describe the application HTML and JavaScript files and break down creation of the application code into steps.</p>

	<ul>
		<li><a href="#DetCreatingHTML">Creating the HTML File</a></li>
		<li><a href="#DetCreatingJS">Creating the Application JavaScript File</a></li>
		<li><a href="#DetTest">Testing the Application</a></li>
		<li><a href="#DetUpdate">Updating the Application for Production</a></li>
		<li><a href="#DetProd">Putting the Application into Production</a></li>
	</ul>

<h3><a name="DetCreatingHTML"></a>Creating the HTML File</h3>
<p>The first step in creating a Sencha Touch application is to create an HTML file that links to Sencha Touch and application CSS files, the Sencha Touch library, and the application JavaScript file.</p>
<p>The GeoTweets application HTML file is <strong>index.html</strong> and its contents are as follows:</p>

<pre>
 &lt;!DOCTYPE html&gt;
 &lt;html&gt;
 &lt;head&gt;
     &lt;meta charset=&quot;utf-8&quot;&gt;
     &lt;title&gt;GeoTweets&lt;/title&gt;

	 &lt;!-- Sencha Touch CSS --&gt;
	 &lt;link rel=&quot;stylesheet&quot; href=&quot;../../resources/css/sencha-touch.css&quot; type=&quot;text/css&quot;&gt;

	 &lt;!-- Custom CSS --&gt;
	 &lt;link rel=&quot;stylesheet&quot; href=&quot;css/guide.css&quot; type=&quot;text/css&quot;&gt;

	 &lt;!-- Google Maps JS --&gt;
	 &lt;script type=&quot;text/javascript&quot; src=&quot;http://maps.google.com/maps/api/js?sensor=true&quot;&gt;&lt;/script&gt;

	 &lt;!-- Sencha Touch JS --&gt;
	 &lt;script type=&quot;text/javascript&quot; src=&quot;../../sencha-touch-debug.js&quot;&gt;&lt;/script&gt;

	 &lt;!-- Application JS --&gt;
	 &lt;script type=&quot;text/javascript&quot; src=&quot;src/index.js&quot;&gt;&lt;/script&gt;


 &lt;/head&gt;
 &lt;body&gt;&lt;/body&gt;
 &lt;/html&gt;
</pre>

<p>The HTML file for the GeoTweets application links to five files:</p>
<ul>
	<li>The default CSS style sheet for Sencha Touch (<strong>sencha-touch.css</strong>).</li>
	<li>The custom application CSS (<strong>guide.css</strong>).</li>
		<p>This document does not describe the CSS file in detail because its properties are straight-forward and should be self-explanatory. Additionally, this document assumes you are familiar with Web application concepts such as CSS.</p>
	<li>The Google Maps library (<strong>http://maps.google.com/maps/api/js?sensor=true</strong>).</li>
	<li>The Sencha Touch library (during development and testing, use the debug version of the Sencha Touch library, <strong>sencha-touch-debug.js</strong>).</li>
		<p>The debug version of the library is not compressed and it contains documentation. This can be helpful if an error occurs, as it allows you to see exactly where in the library the error occurred. Normally, in production, you would use <strong>sencha-touch.js</strong>, which is the version of the library that is optimized for production.</p>
	<li>The application JavaScript file (<strong>index.js</strong>).</li>

</ul>
<p><strong>NOTE</strong>: Notice that the <code>&lt;body&gt;</code> tag in the HTML file is empty. This is because Sencha Touch automatically generates the page content via JavaScript.</p>

<h3><a name="DetCreatingJS"></a>Creating the Application JavaScript File</h3>
<p>Once you have created the HTML file, you are ready to create the application JavaScript file. This section shows the entire contents of the application JavaScript file and breaks down the creation of the application code into steps.</p>

<p>The GeoTweets application JavaScript file is <strong>index.js</strong> and its contents are as follows:</p>

<pre>
Ext.setup({
    tabletStartupScreen: 'tablet_startup.png',
    phoneStartupScreen: 'phone_startup.png',
    icon: 'icon.png',
    glossOnIcon: false,
    onReady: function() {
        var timeline = new Ext.Component({
            title: 'Timeline',
            cls: 'timeline',
            scroll: 'vertical',
            tpl: [
                '&lt;tpl for=&quot;.&quot;&gt;',
                    '&lt;div class=&quot;tweet&quot;&gt;',
                            '&lt;div class=&quot;avatar&quot;&gt;&lt;img src=&quot;{profile_image_url}&quot; /&gt;&lt;/div&gt;',
                            '&lt;div class=&quot;tweet-content&quot;&gt;',
                                '&lt;h2&gt;{from_user}&lt;/h2&gt;',
                                '&lt;p&gt;{text}&lt;/p&gt;',
                            '&lt;/div&gt;',
                    '&lt;/div&gt;',
                '&lt;/tpl&gt;'
            ]
        });

        var map = new Ext.Map({
            title: 'Map',
            getLocation: true,
            mapOptions: {
                zoom: 12
            }
        });

        var panel = new Ext.TabPanel({
            fullscreen: true,
            cardSwitchAnimation: 'slide',
            items: [map, timeline]
        });

        var refresh = function() {
            var coords = map.geo.coords;

            Ext.util.JSONP.request({
                url: 'http://search.twitter.com/search.json',
                callbackKey: 'callback',
                params: {
                    geocode: coords.latitude + ',' + coords.longitude + ',' + '5mi',
                    rpp: 30
                },
                callback: function(data) {
                    data = data.results;

                    // Update the tweets in timeline
                    timeline.update(data);

                    // Add points to the map
                    for (var i = 0, ln = data.length; i < ln; i++) {
                        var tweet = data[i];

                        // If the tweet is geo-tagged, use that to display marker
                        if (tweet.geo && tweet.geo.coordinates) {
                            var position = new google.maps.LatLng(tweet.geo.coordinates[0], tweet.geo.coordinates[1]);
                            addMarker(tweet, position);
                        }
                    }
                }
            });
        };

        // These are all Google Maps APIs
        var addMarker = function(tweet, position) {
            var marker = new google.maps.Marker({
                map: map.map,
                position: position
            });
        };

        map.geo.on('update', refresh);

        var tabBar = panel.getTabBar();
        tabBar.addDocked({
            xtype: 'button',
            ui: 'mask',
            iconCls: 'refresh',
            dock: 'right',
            stretch: false,
            align: 'center',
            handler: refresh
        });

    }
});
</pre>

<p>The JavaScript code in the GeoTweets application file defines:</p>
<ul>
	<li>the application cards, <strong>timeline</strong> and <strong>map</strong>. The <strong>timeline</strong> card is defined as an Ext.Component and it displays tweets in a list. The <strong>map</strong> card is an Ext.Map component and it displays the locations of the tweeters on a map.</li>
	<li>a <strong>TabPanel</strong> component, called <strong>panel</strong> which contains two tabs: <strong>Timeline</strong> (which displays the <strong>timeline</strong> card) and <strong>Map</strong> (which displays the <strong>map</strong> card) within an animated transition for switching between the cards.</li>
	<li><strong>refresh</strong> and <strong>addMarker</strong> functions. The <strong>refresh</strong> function updates the data from Twitter. The <strong>addMarker</strong> function determines the geographic locations of the tweeters to display on the <strong>map</strong> card.</li>
	<li>a custom refresh button.</li>
</ul>

<p><strong>Note</strong>: In this application, components are created with the following syntax:</p>

<pre>    <strong>var</strong> <em>objectName</em> <strong>= new Ext.</strong><em>ComponentName</em><strong>({</strong>
        <em>objectDefinition</em>
    <strong>});</strong> </pre>

<p>where:</p>
	<ul>
		<li><em>objectName</em> is the name of the variable used to reference the object.</li>
		<li><em>ComponentName</em> is the name of the object's class.</li>
		<li><em>objectDefinition</em> defines the object's properties and behavior.</li>
	</ul>

<p>The following sections walk you through the steps for creating the application script.</p>

<ul>
	<li><a href="#DetBeginApp">Beginning the Application Script File</a></li>
	<li><a href="#DetTimeline">Defining the Timeline Card</a></li>
	<li><a href="#DetMap">Defining the Map Card</a></li>
	<li><a href="#DetPanel">Defining the Tab Panel Component</a></li>
	<li><a href="#DetGetData">Getting Data from Twitter</a></li>
	<li><a href="#DetAddMarkers">Adding Tweet Markers to the Map</a></li>
	<li><a href="#DetAddRefreshEv">Adding a Refresh Event</a></li>
	<li><a href="#DetAddCustomBtn">Adding a Custom Refresh Button to the Tab Bar</a></li>
</ul>

<h4><a name="DetBeginApp"></a>Beginning the Application Script File</h4>

<p>In the editor of your choice, begin writing the application script. The first lines of JavaScript code for the application file (<strong>index.js</strong>) are as follows:</p>

<pre>Ext.setup({
    tabletStartupScreen: 'tablet_startup.png',
    phoneStartupScreen: 'phone_startup.png',
    icon: 'icon.png',
    glossOnIcon: false,
    onReady: function() {
</pre>

<p>The <em>Ext.setup</em> method sets up a page for use on a touch-enabled device. It allows you to set various start up properties and behaviors for your application. For detailed information on the Sencha Touch API, including this method, see the <a href="http://www.sencha.com/deploy/touch/docs/">Sencha Touch API Documentation</a>.</p>

<p>The GeoTweets application code specifies the following start up properties:
<ul>
<li><strong>tabletStartupScreen</strong> Property. Specifies the name of the icon file to use as the application's start up screen on tablet devices.</li>
<li><strong>phoneStartupScreen</strong> Property. Specifies the name of the icon file to use as the application's start up screen on phone devices.</li>
<li><strong>icon</strong> Property. Specifies the name of the application's default icon file, <em>icon.png</em>.
</li>
<li><strong>glossOnIcon</strong> Property. Specifies whether you want the <em>gloss</em> effect to be applied to the default icon. In this case, the value is set to <em>false</em> indicating not to add gloss to the default icon.
</li>
<li><strong>onReady</strong> Method. Specifies the function to run when the browser's Document Object Model (DOM) is ready after the application HTML file has loaded.
</li>

Within the function in the <strong>onReady</strong> method, you define the rest of the application code, as explained in the following sections. The rest of the application code consists of:</p>

<ul>
<li>The <strong>timeline</strong> card to display tweets in a list</li>
<li>The <strong>map</strong> card to display tweets on a map</li>
<li>The <strong>panel</strong> Ext.TabPanel container component</li>
<li>A <em>refresh</em> function for updating the tweet data in the cards</li>
<li>An <em>addMarker</em> function for displaying the geographic locations of the
tweeters</li>
<li>A refresh button on the tab bar that uses the <em>refresh</em> function to
get the latest data from Twitter and redisplay it in the cards</li>
</ul>

<h4><a name="DetTimeline"></a>Defining the Timeline Card</h4>

<p>The <strong>timeline</strong> card displays tweets in a list view. It is created as an <em>Ext.Component</em>, which is a generic shell for data and other components or widgets.</p>

<p>The JavaScript for the <strong>timeline</strong> card <em>Ext.Component</em> is as follows:</p>

<pre>    var timeline = new Ext.Component({
        title: 'Timeline',  // Name that appears on this tab
        cls: 'timeline',    // The CSS class. Lets you style elements on the timeline.
        scroll: 'vertical', // Make it vertically scrollable
        tpl: [              // Set up a template to display tweet data
          '&lt;tpl for="."&gt;',
            '&lt;div class="tweet"&gt;',
              '&lt;div class=&quot;avatar&quot;&gt;&lt;img src=&quot;{profile_image_url}&quot; /&gt;&lt;/div&gt;', // Tweeter's picture
              '&lt;div class="tweet-content"&gt;',
                '&lt;h2>{from_user}&lt;/h2&gt;',       // Tweeter's name
                '&lt;p>{text}&lt;/p&gt;',              // Tweeter's message
              '&lt;/div&gt;',
            '&lt;/div&gt;',
        '&lt;/tpl&gt;'
       ]
    });
</pre>

<p>The <strong>timeline</strong> card <em>Ext.Component</em>:</p>
<ul>
	<li>Defines three properties that control the appearance of the card:
	<ul>
		<li><strong>title</strong> Property. Specifies the label <strong>Timeline</strong> to appear on the tab for this component.</li>
		<li><strong>cls</strong> Property. Specifies the CSS class, which you can use to style elements on the timeline.</li>
		<li><strong>scroll</strong> Property. Specifies the direction in which this <em>Ext.Component</em> is scrollable. In this case, it is set to <em>'vertical'</em>, making the card vertically scrollable. For other possible values, see the <a href="http://www.sencha.com/deploy/touch/docs/">Sencha Touch API Documentation</a>. </li>
	</ul>
	</li>
	<li>Defines a template for displaying the tweets. Sencha Touch uses templates to dynamically render information
in components.</li>
</ul>

<p>This template updates the <strong>timeline</strong> card component with data from Twitter. The
template tags, <em>profile_image_url</em>, <em>from_user</em>, and <em>text</em> are enclosed in curly braces ({}) and match the JSON format in which Twitter data is stored. The <em>Ext.util.JSONP.request</em> method retrieves the data.</p>

<p>In the application CSS file, <em>guide.css</em>, you can set and change the way the classes defined in the template code appear on device screens.</p>

<p>The following figure shows a typical timeline card that the application might display:</p>

<img src="examples/resources/shared/getting-started/timeline.jpg" border=5></li>

<h4><a name="DetMap"></a>Defining the Map Card</h4>
<p>The <strong>map</strong> card displays a map of the nearby tweets.</p>
<p>The JavaScript for the <strong>map</strong> card, which is an <em>Ext.Map</em> component, is as follows:</p>

<pre>    var map = new Ext.Map({
        title: 'Map',        // Name that appears on this tab
        getLocation: true,   // Gets user's current location
        mapOptions: {        // Used in rendering map
          zoom: 12
        }
    });
</pre>

<p><em>Ext.Map</em> creates a Google Map component by wrapping a Google Map in an Ext.Component. As with other Ext components, the <em>Ext.Map</em> component defines properties that control the appearance of the card:
<ul>
	<li><strong>title</strong> Property. Specifies that the label <strong>Map</strong> appears on the tab for this component. </li>
	<li><strong>getLocation</strong> Property. Uses the Geolocation utility to automatically get the application user's location and set it as the center of the map. </li>
</ul>
<p><em>Ext.Map</em> also specifies <em>mapOptions</em> which are used in rendering the map. The <em>mapOptions</em> you set as part of an <em>Ext.Map</em> component are passed directly to the Google Map object. For more information on these options and the Google Maps API, see the <a href="http://code.google.com/apis/maps/documentation/v3/reference.html">Google Maps API Documentation</a>.</p>

</p>In this example, the <em>zoom</em> option, which specifies the initial map zoom level, is set to <em>12</em>.
</p>

<p>The following image shows the map card:</p>
<img src="examples/resources/shared/getting-started/map.jpg" border=5></li>

<h4><a name="DetPanel"></a>Defining the Tab Panel Component</h4>
<p><em>Ext.TabPanel</em> is a container component that holds the objects that the application displays. In this case, the <strong>TabPanel</strong> component contains the two previously-defined components <strong>timeline</strong> and <strong>map</strong>, automatically adds tabs with the specified titles (<strong>Timeline</strong> and <strong>Map</strong>) above the cards (components), and provides the logic for switching between the cards.</p>
<p>The <em>Ext.TabPanel</em> application code is as follows:</p>
<pre>    var panel = new Ext.TabPanel({
        fullscreen: true,            // The panel will take up the full rather than partial screen
        cardAnimation: 'slide',       // Special effect for switching between cards
        items: [map, timeline]       // Components (cards) that the tabs correspond with
    });
</pre>

<p>The <strong>TabPanel</strong> card component defines three properties that control the appearance of the tab panel:
	<ul>
		<li><strong>fullscreen</strong> Option. Specifies that this component will take up the full width and height of the screen, and automatically renders the component to the page.
		</li>
		<li><strong>cardSwitchAnimation</strong> Property. Specifies the <em>slide</em> special effect animation to use when switching between cards.
		</li>
		<li><strong>items</strong> Property. Specifies the previously-defined component objects (cards) to add to this container.
		</li>
	</ul>
</p>

<p>The following image shows the effect of switching between the cards in the application:</p>
<img src="examples/resources/shared/getting-started/panel.jpg" border=5><p>There are additional transition effects you can use for changing cards, such as <em>flip</em>, <em>wipe</em>, <em>cube</em>, <em>pop</em> and so forth. For more information, see <a href="http://www.sencha.com/deploy/touch/docs/?class=Ext.anims">the API documentation</a> for the <em>Ext.anims</em> class.</p>

<h4><a name="DetGetData"></a>Getting Data from Twitter</h4>
<p>The <em>refresh</em> function is called when the application starts up and again whenever the <em>refresh</em> button (which you define in a later section) in the application is tapped. The function makes an external request to gather data from Twitter. It also calls an <em>addMarker</em> function that gets the geographic data for adding markers that show tweeter locations on the map.</p>
<p>The corresponding code from the application file is as follows:</p>

<pre>
    var refresh = function() {                           // Define the refresh function

      var coords = map.geo.coords;                       // Define a coords variable from the maps geolocation
      Ext.util.JSONP.request({                           // Make an external call using JSONP
        url: 'http://search.twitter.com/search.json',    // to this URL
        callbackKey: 'callback',                         // Set the required Twitter callback parameter
        params: {
          geocode: coords.latitude + ',' + coords.longitude + ',' + '5mi', // Get lat, long, and radius
          rpp: 30                                        // Number of tweets per page
        },
      callback: function(data) {                         // Provide structure to hold data from Twitter callback
        data = data.results;                             // Hold Twitter info in variable called data
        timeline.update(data.results);                   // Update the tweets in timeline

        for (var i = 0, ln = data.length; i &lt; ln; i++) { // Loop to add points to the map
          var tweet = data[i];                           // Get data for a single tweet

          if (tweet.geo &amp;&amp; tweet.geo.coordinates) {      // If the tweet is geo-tagged, use that to display marker
            var position = new google.maps.LatLng(tweet.geo.coordinates[0], tweet.geo.coordinates[1]);  // Get coords
            addMarker(tweet, position);                  // Call addMarker function with new data
          }
        }
      }
    });
  };
</pre>
<p>The <em>Ext.util.JSONP.request</em> provides an easy way to make a JSON call to Twitter. To it, you pass:
<ul>
	<li>a <strong>url</strong> option. This option specifies the URL to which you want to make an external call using JSONp. The corresponding code is:
	<pre>url: 'http://search.twitter.com/search.json',</pre>
	</li>
	<li>the <strong>callbackKey</strong>. This function runs when data is returned.
	</li>
	<li><strong>params</strong> (parameters). These parameters are passed directly into the request and run a basic search for nearby tweets. The corresponding code is:
	<pre>
	params: {
	          geocode: coords.latitude + ',' + coords.longitude + ',' + '5mi',
          rpp: 30
    </pre>
</li>
<p>The specific parameters used to run a basic search for nearby tweets are:</p>
	<ul>
		<li>the <strong>geocode</strong> parameter, which gets tweeter locations within a five mile radius of the application user.
		</li>
		<li>the <strong>rpp</strong> parameter, which specifies the number of tweets (30 in this case) to return per page of data.
		</li>
	</ul>
</ul>

<p><strong>Note</strong> The <strong>geocode</strong> and <strong>rpp</strong> parameters are specific to the <a href="http://apiwiki.twitter.com/Twitter-Search-API-Method%3A-search">Twitter Search API</a>.</p>


<p>The <em>callback</em> function receives the data from Twitter and stores it in
the <em>data</em> variable. It first updates the <strong>timeline</strong> card with a list of the tweets. Recall that the template defined in the <a href="#DetTimeline">timeline card</a> component looks for {profile_image_url}, {from_user}, and {text},  all of which are defined in the results.</p>
<p>The application code for the <em>callback</em> function is as follows:</p>
<pre>
callback: function(data) {
        data = data.results;
        timeline.update(data.results);
</pre>

<p>The following is an example of the raw data that comes back from Twitter:</p>
<pre>{&quot;results&quot;:
[{&quot;profile_image_url&quot;:&quot;"http://a1.twimg.com/profile_images/704555348/boat3_normal.jpg...
&quot;from_user&quot;:&quot;jonathanjulian&quot;,...
&quot;text&quot;:&quot;@agnellvj have a look at the most intense #extjs book to be published do far!&quot;,
...</pre>

The <em>for</em> loop goes through the Twitter data one tweet
at a time and checks for geographic tagging. If a tweet is geo-tagged,
then the latitude and longitude coordinates are stored in the <em>position</em>
variable and passed to the <em>addMarker</em> function, which adds the tweet
 to the map.</p>
<p>The corresponding code is as follows:</p>
<pre>
 for (var i = 0, ln = data.length; i &lt; ln; i++) {
           var tweet = data[i];

           if (tweet.geo &amp;&amp; tweet.geo.coordinates) {
             var position = new google.maps.LatLng(tweet.geo.coordinates[0], tweet.geo.coordinates[1]);
            addMarker(tweet, position);
</pre>


<h4><a name="DetAddMarkers"></a>Adding Tweet Markers to the Map</h4>
<p>The <em>addMarker</em> function adds tweets to the map based on location. The logic in this function deals almost entirely with the <a href="http://code.google.com/apis/maps/documentation/v3/">Google Maps API</a> and is not specific to Sencha Touch.</p>
<p>The corresponding code from the application file is as follows:</p>

<pre>   var addMarker = function(tweet, position) {        // Define addMarker function
            var marker = new google.maps.Marker({          // Define variable to hold marker data
            map: map.map,
            position: position,
        });
    }
</pre>

<h4><a name="DetAddRefreshEv"></a>Adding a Refresh Event</h4>
<p>The <em>refresh</em> function runs each time the Geolocation utility within the map is updated. Because you set <em>getLocation: true</em> on the Map component, <em>refresh</em> runs immediately after the page has loaded and has retrieved the application user's location.</p>

<p>The corresponding code, which specifies when <em>refresh</em> runs is as follows:</p>

<pre>
    map.geo.on('update', refresh);
</pre>

<p><strong>Note</strong>: The Twitter API often serves cached data and refreshes periodically, which means that new tweets may not always display each time a user taps the refresh button.</p>

<h4><a name="DetAddCustomBtn"></a>Adding a Custom Refresh Button to the Tab Bar</h4>

<p>To add the custom refresh button to the Tab Bar, first retrieve the TabBar portion of the TabPanel with the following code:</p>
<pre>
    var tabBar = panel.getTabBar();
</pre>

<p>The following image shows the Tab Bar.</p>

<img src="examples/resources/shared/getting-started/tabbar.png" border=5>

<p>This section describes a technique for creating a custom refresh button as a docked item
on the GeoTweets application tab bar.</p>

<p>To add a button to the TabBar, create a component by passing an object directly to the <em>addDocked</em> function. By using an <em>xtype</em> property in this object, you can create the new button on the fly, inline with the code. This functionality is found throughout the library. Any place where you would typically insert a component or widget, you can also use a flat object with the configuration properties and an <em>xtype</em> property. While using this technique is a fast way to generate interfaces, it can also be less maintainable.</p>

<pre>
    tabBar.addDocked({
        xtype: 'button',          // Specifies an instance of the button class
        ui: 'mask',              // Appearance, for example, "light", "dark", etc.
        iconCls: 'refresh',       // CSS class for the button
        dock: 'right',            // Puts the new button at the right of the tab bar
        stretch: false,           // Prevents the button from stretching to full height of tab bar
        align: 'center',          // Centers the button vertically within the tab bar
        handler: refresh          // Refreshes the current card when users tap
    });
</pre>

<p>There are several properties that control the layout of docked objects. The GeoTweets application uses the following properties:
	<ul>
		<li><strong>ui</strong> Property. Controls the appearance of the UI.
		</li>
		<li><strong>iconCls</strong> Property. Specifies the CSS class for the button.
		</li>
		<li><strong>dock</strong> Property. Controls the horizontal (left to right) position of a docked object. In this example, it is set to <em>'right'</em>, which positions the button horizontally on the right side of the tab bar.
		</li>
		<li><strong>stretch</strong> Property. Defines whether a docked object maintains a fixed height or whether its height stretches as the tab bar's height changes when it is resized. In this example, the property is set to <em>false</em>, which specifies that the docked button maintains a fixed height regardless of whether the tab bar is resized.
		</li>
		<li><strong>align</strong> Property. Controls the vertical (top to bottom) position of a docked object. In this example, the property is set to <em>'center'</em>, which centers the object vertically on the tab bar.
		</li>
	</ul>
<p>Additionally, the <em>handler</em> function is called when an application user taps the button. In this application, we specify that the <em>refresh</em> function is called when the button is tapped.</p>

<p>The following image shows the button you defined:</p>
<img src="examples/resources/shared/getting-started/button.png" border=5>

<h3><a name="DetTest"></a>Testing the Application</h3>
<p>Once you have finished writing and have saved the application JavaScript file you are ready to test it. To do so, follow the directions in <a href="#MainTest">Test the Application</a>.</p>

<h3><a name="DetUpdate"></a>Updating the Application for Production</h3>
<p>When you are done testing your application, follow the directions in <a href="#MainUpdateForProd">Update the Application for Production</a> to change from the debug to the production version of the Sencha Touch library.</p>

<h3><a name="DetProd"></a>Putting the Application into Production</h3>

<p>When you are ready to release your application for general use, follow the directions in <a href="#MainPutIntoProd">Put the Application into Production</a>.


<h2><a name="Summary"></a>Summary and Further Reading</h2>

<p>As you can see, creating JavaScript Web applications with Sencha Touch is quick and simple! The Sencha Touch release package includes many other examples you can browse and learn from.</p>

<p>For further information on the topics covered in this document, see:
<ul>
	<li><a href="http://www.sencha.com/deploy/touch/docs/">The Sencha Touch API Documentation</a></li>
	<li><a href="http://www.sencha.com/forum/">The Sencha Forums</a></li>
	<li><a href="http://www.sencha.com/">www.sencha.com</a></li>

	<li><a href="http://apiwiki.twitter.com/">The Twitter API Documentation</a></li>
	<li><a href="http://code.google.com/apis/maps/documentation/v3/">The Google Maps API Documentation</a></li>
</ul>

<hr />

<p><small>This file last updated July 26, 2010.</small></p>

</body>
</html>
